package com.example.menudemo;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;

/**
 * @author wdl
 */
public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        TextView tvMenu = findViewById(R.id.tv_menu);
        //注册context menu
        registerForContextMenu(tvMenu);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.action_test1:
                break;
            case R.id.action_test2:
                break;
            case R.id.action_test3:
                break;
            case R.id.action_test4:
                break;
            case R.id.action_test5:
                break;
            default:
        }
        return super.onOptionsItemSelected(item);
    }

    /**
     * Context menu
     */

    @Override
    public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
        getMenuInflater().inflate(R.menu.main, menu);
        super.onCreateContextMenu(menu, v, menuInfo);
    }

    @Override
    public boolean onContextItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.action_test1:
                break;
            case R.id.action_test2:
                break;
            case R.id.action_test3:
                break;
            case R.id.action_test4:
                break;
            case R.id.action_test5:
                break;
            default:
        }
        return super.onContextItemSelected(item);
    }
}
